package cn.itrip.service.impl;

import cn.itrip.entity.ItripHotelRoom;
import cn.itrip.dao.ItripHotelRoomDao;
import cn.itrip.service.ItripHotelRoomService;
import cn.itrip.vo.HotelRoomVO;
import com.fasterxml.jackson.databind.util.BeanUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 酒店房间表(ItripHotelRoom)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:56
 */
@Service("itripHotelRoomService")
public class ItripHotelRoomServiceImpl implements ItripHotelRoomService {
	@Resource
	private ItripHotelRoomDao itripHotelRoomDao;

	@Override
	public List<List<HotelRoomVO>> queryhotelroombyhotel(Map<String, String> from) {
		List<ItripHotelRoom> itripHotelRooms = itripHotelRoomDao.queryHotelRoomByHotel(from);

		List list = new ArrayList();
		itripHotelRooms.stream().forEach(r -> {
			List<HotelRoomVO> hotelRoomVOS = new ArrayList<>();
			HotelRoomVO hotelRoomVO = new HotelRoomVO();
			BeanUtils.copyProperties(r,hotelRoomVO);
			hotelRoomVOS.add(hotelRoomVO);

			list.add(hotelRoomVOS);
		});
		return list;
	}

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripHotelRoom queryById(Long id) {
		return this.itripHotelRoomDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripHotelRoom 筛选条件
	 * @param pageRequest    分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripHotelRoom> queryByPage(ItripHotelRoom itripHotelRoom, PageRequest pageRequest) {
		long total = this.itripHotelRoomDao.count(itripHotelRoom);
		return new PageImpl<>(this.itripHotelRoomDao.queryAllByLimit(itripHotelRoom, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripHotelRoom 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripHotelRoom insert(ItripHotelRoom itripHotelRoom) {
		this.itripHotelRoomDao.insert(itripHotelRoom);
		return itripHotelRoom;
	}

	/**
	 * 修改数据
	 *
	 * @param itripHotelRoom 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripHotelRoom update(ItripHotelRoom itripHotelRoom) {
		this.itripHotelRoomDao.update(itripHotelRoom);
		return this.queryById(itripHotelRoom.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripHotelRoomDao.deleteById(id) > 0;
	}
}
